﻿using System.Collections.Generic;
using System.Web.UI;
using EPiServer.Shell.ViewComposition;
using OpenWaves.Web;

namespace OpenWaves.EPiServer.ImageBrowser
{
    [Component]
    public class ImageBrowserWidget : ComponentDefinitionBase
    {
        public const string ClientClass = "ow-epi-imageBrowser.imageBrowserWidget";

        public ImageBrowserWidget()
            : base(ClientClass)
        {
            this.Title = "Image browser";
            this.Categories = (IEnumerable<string>)new string[1]
                {
                    "cms"
                };
        }

        public override IComponent CreateComponent()
        {
            var component = base.CreateComponent();

            component.Settings.Add(new Setting("FileControllerUrl", ImageBrowserController.GetControllerPath(), false));

            var availableVpp = new AvailableVpp();
            component.Settings.Add(new Setting("VppListing", availableVpp.GetVppListing(), false));
            
            AssemblyResourceVirtualPathProvider.EnsureRegistered();
            var control = new Control();
            var dialogUrl =
                AssemblyResourceVirtualPathProvider.CreateUrl(
                    typeof(OpenWaves.EPiServer.ImageBrowser.FileSummaryDialogDialog.EditFileSummary)).ToString();
            dialogUrl = control.ResolveUrl(dialogUrl);
            component.Settings.Add(new Setting("FileSummaryDialogUrl", dialogUrl, false));

            return component;
        }

        public override bool SupportsAutomaticRegistration
        {
            get
            {
                return true;
            }
        }
    }
}